<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page import= "java.util.Date" %>



<c:set var="currentDate" value="<%=new Date() %>"/> <!-- 오늘 -->
<c:set var="currentTime" value="<%=new Date(new Date().getTime()) %>"/> <!-- 오늘 -->
<c:set var="fromDate" value="<%=new Date(new Date().getTime() - (1 * 1000 * 60 * 60 * 24))%>"/> <!-- 이전일 -->

<c:set var="userId" value="${user.userId }" />
<c:set var="userNm" value="${user.userNm }" />
<c:set var="postnTeamCode" value="${user.postnTeamCode }" />
<c:set var="postnTeamName" value="${user.postnTeamName }" />
<c:set var="postnPartCode" value="${user.postnPartCode }" />
<c:set var="postnPartName" value="${user.postnPartName }" />
<c:set var="postnCrewCode" value="${user.postnCrewCode }" />
<c:set var="postnCrewName" value="${user.postnCrewName }" />

<fmt:formatDate value="${currentDate}" var="currentDate" type="date" pattern="yyyy-MM-dd" />
<fmt:formatDate value="${fromDate}" var="fromDate" type="date" pattern="yyyy-MM-dd" />
<fmt:formatDate value="${currentTime}" var="currentTime" type="time" pattern="HHmm" />

<script type="text/javascript">
<!--
/* ******************************************************************
*  전역변수 선언
* ****************************************************************** */
$.jgrid.no_legacy_api = true;
$.jgrid.useJSON = true; 

var url = "/counsel/cns/";
var sData;

/* ******************************************************************
*  이벤 트 함수
* ****************************************************************** */

/* ******************************************************************
*   window_onload 이벤트
* ****************************************************************** */
$(document).ready(function(){

	sData = window.dialogArguments;
	
	
	btnSrch.focus();
	
	//처음 페이지 로딩
	Init();
	
});

/* ******************************************************************
*  그리드 디자인 및 이벤트
* ****************************************************************** */
/* ===========================
 * 그리드 디자인 및 데이터 바인딩
 * =========================== */
function drawGrid () {

	$("#gridList").jqGrid("GridUnload");			// 리드 초기화
	$("#gridList").clearGridData();			// 리드 초기화

	$("#gridList").jqGrid({							//gridList 테이블에 jqgrid
    	datatype: "local",							//json 방식으로 가져온다
        //mtype: "GET",
        //height: "auto",
        //autowidth: false,
        //shrinkToFit:false,
        //width: "300",
    	// 이 구문이 있어야 JSON 데이터를 받아온다.
    	/*
        height: "auto",
        rownumbers: true, // 행번호 사용여부
        //toolbar : [true,"top"],
        scroll: 1,
        rowNum: 2,
        viewrecords:true,						//총 레코드의 수를 표시할지 여부
        multiselect: false,						//select box를 추가할지 여부
        loadonce:true,							//서버에서 데이터를 한번만 로그
        */
        //width: 749,
    	height: 140,
      	rowNum:1000,          //검색 row 개수
      	forceFit:true, // 가로스크롤
      	shrinkToFit:false,  //우측스크롤바 위의 조그만 공간 없애고 거기까지 width채움  // 가로스크롤
      	rownumbers:true,       //맨앞에 줄번호 보이기 여부
        rownumWidth:20,        //줄번호의 width      
		autowidth: true,	
		//rowTotal : -1,
       	sortname: 'rrv_dt',
        viewrecords: true,
        sortorder: "desc",
    	//caption: "Invoice Header",
    	//multiselect: true,
    	//multiboxonly: true,
       	//pager: '#pager7',
       	loadtext:'Loading...',
    	jsonReader: {repeatitems:false,ID:"ID",root:function(obj) {return obj;}},
    	
    	colNames:['통화예약번호','예약일자','예약시간','회원번호','회원명','전화구분','전화구분','전화번호','처리구분','처리구분','처리일시','등록자','등록자','처리 담당자 ID','예약 메모'],
    	
        colModel:[
            {name:'crnc_pctr_no'   ,index:'crnc_pctr_no'   ,align:"center", width:"0px", hidden:true },
            {name:'rrv_dt'         ,index:'rrv_dt'         ,align:"center", width:"85px",
	        	 formatter: function(cellvalue, options, rowObject){ 
		        		if (cellvalue) {
		        			return cellvalue.substring(0,4) + "-" + cellvalue.substring(4,6)+"-"+cellvalue.substring(6,8);
		        		} else {
		        			return "";
		        		}
		        	}	
            },
            {name:'rrv_tm'         ,index:'rrv_tm'         ,align:"center", width:"60px",
	        	 formatter: function(cellvalue, options, rowObject){ 
		        		if (cellvalue) {
		        			return cellvalue.substring(0,2) + ":" + cellvalue.substring(2,4);
		        		} else {
		        			return "";
		        		}
		        	}	
            },
            {name:'cus_no'         ,index:'cus_no'         ,align:"center", width:"70px"},
            {name:'mmb_nm'         ,index:'mmb_nm'         ,align:"center", width:"80px"},
            {name:'pctr_telplce_dv',index:'pctr_telplce_dv',align:"center", width:"80px", hidden:true},
            {name:'pctr_telplce_dv_nm',index:'pctr_telplce_dv_nm',align:"center", width:"80px"},
            {name:'rrv_tel_no'     ,index:'rrv_tel_no'     ,align:"center", width:"100px",
	        	 formatter: function(cellvalue, options, rowObject){ 
		        		if (cellvalue) {
		        			return maskPhone(cellvalue);
		        		} else {
		        			return "";
		        		}
		        	}	
            		
            },
            {name:'ps_dv'          ,index:'ps_dv'          ,align:"center", width:"70px", hidden:true},
            {name:'ps_dv_nm'          ,index:'ps_dv_nm'          ,align:"center", width:"70px"},
            {name:'ps_dt_tm'       ,index:'ps_dt_tm'       ,align:"center", width:"130px",
	        	 formatter: function(cellvalue, options, rowObject){ 
		        		if (cellvalue) {
		        			return cellvalue.substring(0,4) + "/" + cellvalue.substring(4,6)+"/"+cellvalue.substring(6,8)+" "+cellvalue.substring(8,10)+":"+cellvalue.substring(10,12)+":"+cellvalue.substring(12,14);
		        		} else {
		        			return "";
		        		}
		        	}	
            },
            {name:'regp_nm'        ,index:'regp_nm'        ,align:"center", width:"100px"},
            {name:'regp_id'        ,index:'regp_id'        ,align:"center", width:"100px", hidden:true},
            {name:'ps_user_id'     ,index:'ps_user_id'     ,align:"center", width:"10px", hidden:true},
            {name:'rrv_memo'       ,index:'rrv_memo'       ,align:"center", width:"10px", hidden:true }
            
            
            
        ]
			
    });
	
	getCallList ();
}

/* ===========================
 * 그리드 데이터 바인딩
 * =========================== */
function getCallList () {

	$('.loading').show();
	
	var rrv_dt_strt = $("#rrv_dt_strt").val().replace(/\-+/g,'');
	var rrv_dt_end  = $("#rrv_dt_end").val().replace(/\-+/g,'');
	var ps_user_id  = $("#userId").val();
	
	$.getJSON("cns0110.getCallList"
			,{ "rrv_dt_strt"  : rrv_dt_strt   // 예약일자
			  ,"rrv_dt_end"   : rrv_dt_end    // 예약일자
			  ,"ps_user_id"   : ps_user_id    // 처리 담당자 ID
		     }
			,function (resultJson) {
				$('.loading').hide();
				

				$("#gridList").clearGridData();			// 리드 초기화
			    $("#gridList").jqGrid('setGridParam',{							//gridList 테이블에 jqgrid
			    	data: resultJson,
			    	datatype: "local",							//json 방식으로 가져온다

			        loadError:function(xhr, status, error){	//데이터가 없을경우 출력
						alert("데이터 로드에 실패 했습니다. 다시 시도하시기 바랍니다.");
					},
					loadComplete: function(data) {

						//var rowCnt = $("#gridList").getDataIDs().length;
						
						//if(rowCnt < 1){
						//}
						//else{
							//USER_Btn_false(btnI10, false);		//대분류신규
							//USER_Btn_false(btnI11, true);		//대분류저장	
						//}


						
					},
					ondblClickRow: function(rowid, iRow, iCol, e){ 

						
					},

					onSelectRow: function(rowid){

						ret = $("#gridList").jqGrid('getRowData',rowid);
						//$("#gridList").jqGrid('setRowData',ret.crnc_pctr_no,{rrv_tm:"<font color='red'>Row 13 is updated!</font>"});

						$("#txtCustno"   ).val(ret.cus_no               ); // 회원번호
						$("#txtCustnm"   ).val(ret.mmb_nm               ); // 회원명
						$("#datepicker3" ).val(ret.rrv_dt               ); // 예약일자
						$("#selHh"       ).val(ret.rrv_tm.substring(0,2)); // 예약시
						$("#selMi"       ).val(ret.rrv_tm.substring(3,5)); // 예약분
						$("#txtTelno"    ).val(ret.rrv_tel_no           ); // 예약전화번호
						$("#txaMemo"     ).val(ret.rrv_memo             ); // 메모
						$("#selTelDv"    ).val(ret.pctr_telplce_dv      ); // 예약 전화장소 구분
						$("#ps_user_id"  ).val(ret.ps_user_id           ); // 처리담당자ID
						$("#crnc_pctr_no").val(ret.crnc_pctr_no         ); // 예약번호
						$("#ps_dv"       ).val(ret.ps_dv                ); // 처리구분
						
 
					}
			    }).trigger('reloadGrid');
	});
}
/* ******************************************************************
*  사용자 정의 함수
* ****************************************************************** */
/* ===========================
 * 화면초기화
 * =========================== */
function Init(){


	setInit();

	drawGrid ();		// 그리드 셋팅
	
}

function setInit()
{
	$("#cnsl_no").val(sData.cnsl_no);    // 상담번호
	$("#txtCustno").val(sData.mmb_no);    // 회원번호
	$("#txtCustnm").val(sData.custnm);    // 회원명
	//$("#txtTelno" ).val(sData.hmtel);     // 자택전화
	//sData.etctel    // 기타(직접입력)
	
	$("#selHh").selectOptionTimeHHMM(0, 23, "18");
	$("#selMi").selectOptionTimeHHMM(0, 59, "00");
	
	$("#selHh" ).val("${currentTime}".substring(0,2));
	$("#selMi" ).val("${currentTime}".substring(2,4));

}
// 전화구분에 따른 전화번호 셋팅 및 inputbox 비활성화 처리
function setTelno()
{

	var telDv = $("#selTelDv").val();
	
	switch (telDv)
	{
		// 자택
		case "PLCE001":
			
			$("#txtTelno").val(sData.hmtel);
			$("#txtTelno").attr("readonly", true);
			
		break;
		// 휴대폰
		case "PLCE003":

			$("#txtTelno").val(sData.mobtel);
			$("#txtTelno").attr("readonly", true);
			
		break;
		default:
			$("#txtTelno").val("");
			$("#txtTelno").attr("readonly", false);
			$("#txtTelno").focus();
			
	}
	
}


$(function() {
	

	$("#txaMemo").keyup(function(){
	  $("#txaMemo").checkbyte({
	   //indicator:$("#indicator"),  // 숫자표시하는영역
	   limit:500,      // 체크바이트수
	   twice:false     // 2건체크여부
	  });
	 });

	
	// 전화구분에 따른 전화번호 셋팅 및 inputbox 비활성화 처리
	$("#selTelDv").change(function(){
		setTelno();;
	});	
	
	
	
	//datepicker 달력 두개일 때
	//datepicker 달력 두개일 때
	$( "#rrv_dt_strt" ).datepicker({
		onClose: function( selectedDate ) {
			$( "#rrv_dt_end" ).datepicker( "option", "minDate", selectedDate );
		}
	});
	$( "#rrv_dt_end" ).datepicker({
		onClose: function( selectedDate ) {
			$( "#rrv_dt_strt" ).datepicker( "option", "maxDate", selectedDate );
		}
	});
	$( "#datepicker3" ).datepicker({
		onClose: function( selectedDate ) {
			$( "#datepicker4" ).datepicker( "option", "maxDate", selectedDate );
		}
	});
	
	/* ===========================
	 * 조회 버튼 클릭 이벤트
	 * =========================== */
	$("#btnSrch").click(function()
	{

		// 폼내에 컨트롤 초기화
		﻿$("#rrvForm").gControlReset();
		$("#datepicker3").val("${currentDate}");
		
		setInit();
		
		getCallList();
	});
	
	
	/* ===========================
	 * 초기화 버튼 클릭 이벤트
	 * =========================== */	
	$("#btnNew").click( function() {
		
		
		// 폼내에 컨트롤 초기화
		﻿$("#rrvForm").gControlReset();

		$("#datepicker3").val("${currentDate}");
		
		setInit();

	});
	
	$("#searchUserInfo").click(function(){
		if(!isNull($("#ps_dv").val())) 
		{
			alert("처리자를 수정할 수 없습니다.");
			return;
		}
		searchSecurityInfo("ps_user_id","searchUserNm","ps_team_cd","ps_part_cd","ps_crew_cd","","","");
	});	
	
	/* ===========================
	 * 저장 버튼 클릭 이벤트
	 * =========================== */
	$("#btnSave").click(function()
	{
		var crnc_pctr_no   = $("#crnc_pctr_no").val();
		var cus_no         = $("#txtCustno").val();
	    var cnsl_no        = $("#cnsl_no").val();
	    var mmb_nm         = $("#txtCustnm").val();
	    var rrv_dt         = $("#datepicker3").val().replace(/\-+/g,'');
	    var rrv_tm         = $("#selHh :selected").val() + $("#selMi :selected").val();
	    var pctr_telplce_dv= $("#selTelDv :selected").val();
	    var rrv_tel_no     = $("#txtTelno").val().replace(/\-+/g,'');
	    var rrv_memo       = $("#txaMemo").val();
	    var reg_team_cd    = $("#reg_team_cd").val();
	    var reg_part_cd    = $("#reg_part_cd").val();
	    var reg_crew_cd    = $("#reg_crew_cd").val();
	    var reg_user_id    = $("#userId").val();
	    var ps_team_cd     = $("#ps_team_cd").val();
	    var ps_part_cd     = $("#ps_part_cd").val();
	    var ps_crew_cd     = $("#ps_crew_cd").val();
	    var ps_user_id     = $("#ps_user_id").val();
	    var regp_id        = $("#userId").val();
	    var ps_dv          = $("#ps_dv").val();
	    
	    if(isNull(trim(rrv_tel_no)))
	    {
			alert("예약 전화번호를 입력해 주십시오.");
			return;
	    }

	    if(!isNull(crnc_pctr_no))
	    {
	    	if(ps_dv == "PSDV002")
	    	{
	    		alert("이미 처리된 예약건입니다.");
	    		return;
	    	}
	    	
	    	if(!confirm("수정 하시겠습니까?")) return;
	    }
	    else
	    {
	 		if(!confirm("저장 하시겠습니까?")) return;
	    }
	    
		 $.ajax({
			  type:'POST'
			  ,url:url+"cns0090.setCustRrvInfo"
			  ,data:{i_crnc_pctr_no   : crnc_pctr_no
				    ,i_cus_no         : cus_no
				    ,i_cnsl_no        : cnsl_no
				    ,i_mmb_nm         : mmb_nm
				    ,i_rrv_dt         : rrv_dt
				    ,i_rrv_tm         : rrv_tm
				    ,i_pctr_telplce_dv: pctr_telplce_dv
				    ,i_rrv_tel_no     : rrv_tel_no
				    ,i_rrv_memo       : rrv_memo
				    ,i_reg_team_cd    : reg_team_cd
				    ,i_reg_part_cd    : reg_part_cd
				    ,i_reg_crew_cd    : reg_crew_cd
				    ,i_reg_user_id    : reg_user_id
				    ,i_ps_team_cd     : ps_team_cd
				    ,i_ps_part_cd     : ps_part_cd
				    ,i_ps_crew_cd     : ps_crew_cd
				    ,i_ps_user_id     : ps_user_id
				    ,i_regp_id        : regp_id
				    }
			  ,async:false
			  ,dataType:"html"
			  ,success:function(data,textStatus) {
				alert("통화예약 등록 완료 되었습니다.");
				getCallList();
			  }
		 	  ,error:function() {
				alert("[통화예약 등록오류]\n\n관리자에게 문의해 주십시오.");

			  }
			 });
	});
	
	
});
-->
</script>



<div class="ly_pop" style="width:932px;">
	<!-- pop title s -->
	<div class="pop_title">
		<h1>통화예약등록111</h1>
		<img src="/images/admin/default/content/btn_ly_close.gif" class="close_layer" alt="닫기"  onclick="self.close();"/>
		<div class="pop_title_right"></div>
	</div>
	<!-- // pop title e -->
	<!-- pop contents s -->
	<div class="pop_body" style="height:417px;">
		<!--  .table_rightA s -->
		<div class="table_rightA marT10">
			<div class="titlDot">
				<span class="dayTxt"><span class="txtG">예약일자</span><input id="rrv_dt_strt" class="text w77" title="기간 입력" value="${currentDate}" type="text" /> <span class="txtG">~</span> <input id="rrv_dt_end" class="text w77" title="기간 입력" value="${currentDate}" type="text" /></span>
				<span class="conBtnT01">
					<span class="btnY"><button type="button" id="btnSrch">조회</button></span>
				</span>
			</div>

			<!-- 통화예약 리스트 -->
	        <div style="width:100%; border:#c0c0c0 solid 1px; position:relative; left:0px; height:160px; top:0px; padding-bottom:10px;">
				<table id="gridList"></table>
	        </div>
			<!--// 통화예약 리스트 -->

			<table summary="통화예약 상세" class="tb_type marT15">
				<caption>통화예약 상세</caption>
				<colgroup>
					<col width="100" />
					<col width="180" />
					<col width="100" />
					<col width="*" />
					<col width="100" />
					<col width="180" />
				</colgroup>
<form id="rrvForm" name="rrvForm">				
				<tbody>
					<tr>
						<th scope="row"><em>회원번호</em></th>
						<td>
							<div class="field">
								<input class="text_n w85p NoClear" id="txtCustno" title="회원번호" value="" type="text" disabled/>
							</div>
						</td> 
						<th scope="row"><em>회원명</em></th>
						<td>
							<div class="field">
								<input class="text_n w66p NoClear" id="txtCustnm" title="회원명" value="" type="text" disabled/>
							</div>
						</td>
						<th scope="row"><em>처리자</em></th>
						<td>
							<div class="field">
								<input class="text_e w66p NoClear" id="searchUserNm" title="처리자 등록" value="${userNm }" type="text" readOnly/>
								<a href="#searchUserInfo" id="searchUserInfo"><img src="/images/front/counsel/btn/btn_user.gif" alt="사용자 조회" /></a>
								
								
							</div>
						</td>
					</tr>
					<tr>
						<th scope="row"><em>예약일자</em></th>
						<td>
							<div class="field">
								<input id="datepicker3" class="text w77" title="기간 입력" value="${currentDate}" type="text" />
							</div>
						</td>
						<th scope="row"><em>예약전화</em></th>
						<td>
							<div class="field">
								<select class="w35p" id="selTelDv">
									<option value="">선택</option>
									<c:forEach var="CNS0000016Result" items="${CNS0000016}" varStatus="status">
										<option value="${CNS0000016Result.lowrCd }" >${CNS0000016Result.cdNm }</option>
									</c:forEach>
								</select>
								<input class="text_e w50p required" id="txtTelno" title="전화번호 입력" value="" type="text" maxlength="13" readonly/>
							</div>
						</td>
						<th scope="row"><em>예약시간</em></th>
						<td>
							<div class="field">
								<select class="w35p marR0" id="selHh"><!-- [0505_수정] class 추가 -->
									<option value="">선택</option>
								</select>
								시
								<select class="w35p marR0" id="selMi"><!-- [0505_수정] class 추가 -->
									<option value="">선택</option>
								</select>
								분
							</div>
						</td>
					</tr>
					<tr class="lastLine02"><!-- [0409_수정] 클래스명 추가 -->
						<th scope="row"><em>메모</em></th>
						<td colspan="5">
							<div class="field">
								<textarea name="txaMemo" id="txaMemo" style="ime-mode:active" cols="100" rows="27" class="textarea_e cns10txA" ></textarea>
							</div>
						</td>
					</tr>
				</tbody>
			
				<input type="hidden" name="crnc_pctr_no" id="crnc_pctr_no"  value=""/> <!-- 통화예약번호 -->
				<input type="hidden" name="ps_dv"        id="ps_dv"        value="" /> <!-- 처리구분 -->
</form>	 
			</table>
		</div>
		<!-- // .table_rightA e -->
		<!-- .btnR s -->
		<div class="ar">
			<span class="btn_gy02"><button type="button" id="btnNew" >신규</button></span>
			<span class="btn_gy02"><button type="button" id="btnSave">저장</button></span>
		</div>
		<!-- .btnR e -->
	</div>
	<!-- // pop contents e -->
</div>
<input type="hidden" name="cnsl_no"      id="cnsl_no"      value="" />
<input type="hidden" name="userId"       id="userId"       value="${userId }" /> <!-- 로그인상담원ID -->
<input type="hidden" name="reg_team_cd"  id="reg_team_cd"  value="${postnTeamCode }" />
<input type="hidden" name="reg_part_cd"  id="reg_part_cd"  value="${postnPartCode }" />
<input type="hidden" name="reg_crew_cd"  id="reg_crew_cd"  value="${postnCrewCode }" />

<input type="hidden" name="ps_user_id"   id="ps_user_id"   value="${userId }" />
<input type="hidden" name="ps_team_cd"   id="ps_team_cd"   value="${postnTeamCode }" />
<input type="hidden" name="ps_part_cd"   id="ps_part_cd"   value="${postnPartCode }" />
<input type="hidden" name="ps_crew_cd"   id="ps_crew_cd"   value="${postnCrewCode }" />
